function nimage = fsb_resize_idat(oidat, hidat,tsfx,tsfy,shiftx,shifty,gopt)

% FSB : resize images 
%
% EXAMPLE:
% nimage = fsb_resize_idat(oidat, hidat,tsfx,tsfy,shiftx,shifty,gopt)
%
% INPUT:
% oidat:    original lowres image
% hidat:    original hires image
% tsfx:     scaling factor x
% tsfy:     scaling factor y
% shiftx:   shift in x
% shifty:   shift in y
% gopt:     graphics output?
%
% OUTPUT:
% nimage:   resized image
%
% CALLED by:
% fsb_map_overlay.m
%
% Copyright 2010 MPI for Biological Cybernetics
% Author: Steffen Stoewer
% License: GNU GPL, no express or implied warranties
% 
%$ Revision 1.0
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[a b c] = size(hidat);

%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% determine how much to cut out from the low -res image to account for
% distortion
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

zerof = size(oidat,1)*tsfx; 

zerof = round(zerof);
oidat(1:zerof-shiftx,:,:)=[];
oidat(end-zerof:end,:,:)=[];

%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% determine how much to cut out from the low -res image to account for
% distortion
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

zerof = size(oidat,2)*tsfy; 
zerof = round(zerof);
oidat(:,1:zerof-shifty,:)=[];
oidat(:,end-zerof:end,:)=[];

%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% resize the cut-down low-res image to the dimensions of the hires image
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

nimage = imresize(oidat(:,:,round(c/2)), [a b]); 

end
